package com.pureut.system.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.system.domain.MaterialBomDetail;
import com.pureut.system.domain.MaterialBomDetailApi;
import com.pureut.system.domain.dto.MaterialBomDto;
import com.pureut.system.domain.vo.MaterialBomVo;
import com.pureut.system.service.IMaterialBomService;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description bom信息
 * @Param
 * @Date 22-12-01
 * @Author hl
 **/
@RestController
@RequestMapping("/bom")
public class MaterialBomController extends BaseController {

    @Resource
    private IMaterialBomService materialBomService;


    /**
     * 获取BOM配置
     */
    @RequiresPermissions("material:bom:list")
    @GetMapping("/list")
    public TableDataInfo list(MaterialBomVo materialBomVo) {
        startPage();
        List<MaterialBomDto> list = materialBomService.selectBomList(materialBomVo);
        return getDataTable(list);
    }


    /**
     * 新增Bom信息
     */
    @RequiresPermissions("material:bom:add")
    @Log(title = "Bom信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody MaterialBomVo materialBomVo) throws Exception {
        return toAjax(materialBomService.insertBom(materialBomVo));
    }

    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("material:bom:query")
    @GetMapping(value = "/{bomId}")
    public AjaxResult getBomInfo(@PathVariable long bomId) {
        return AjaxResult.success(materialBomService.getBomInfo(bomId));
    }


    /**
     * 修改bom信息
     */
    @RequiresPermissions("material:bom:edit")
    @Log(title = "bom信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody MaterialBomVo materialBomVo) throws Exception {
        return toAjax(materialBomService.updateMaterialBomEdit(materialBomVo));
    }

    /**
     * 删除bom信息
     */
    @RequiresPermissions("material:bom:remove")
    @Log(title = "bom信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bomId}")
    public AjaxResult remove(@PathVariable("bomId") String bomId) throws Exception {
        return toAjax(materialBomService.deleteMaterialBomById(bomId));
    }


    /**
     * 获取BOM明细
     */
    @RequiresPermissions("material:bom:listDetail")
    @GetMapping("/listDetail")
    public TableDataInfo listDetail(long bomId) {
        startPage();
        List<MaterialBomDetail> list = materialBomService.selectlBomDetailList(bomId);
        return getDataTable(list);
    }


    /**
     * 获取BOM明细(辅料)
     */
    @GetMapping("/listDetailAm")
    public TableDataInfo listDetailAm(long bomId) {
        startPage();
        List<MaterialBomDetail> list = materialBomService.selectlBomDetailListAll(bomId);
        return getDataTable(list);
    }

    /**
     * 获取BOM信息(库存量)
     */
    @GetMapping("/detailInventory")
    public AjaxResult listDetailInventory(long bomId) {
        return AjaxResult.success(materialBomService.selectlBomDetailListInventory(bomId));
    }

    /**
     * 获取BOM信息(根据物料编码)
     */
    @GetMapping("/detailComposition")
    public AjaxResult listComposition(String materialCode) {
        return AjaxResult.success(materialBomService.selectBomDetailComposition(materialCode));
    }

    /**
     * 根据编码获取半成品bom信息(fegin调用)
     */
    @GetMapping("/getHalfData")
    public AjaxResult getHalfData(String materialCode) {
        return AjaxResult.success(materialBomService.getHalfData(materialCode));
    }

}
